﻿function init() {
    gettreelist();
  
}
var _menudata = [];
//#region 加载菜单数据
function gettreelist() {
    var ss = document.getElementById("hidPID").value;
    //网页宽度
    var screenwidth = document.body.clientWidth-2;
    //网页高度
    var screenHeight = window.screen.availHeight-110;
    $.ajaxHandler({
        url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
        urlType: "QueryTreeByPID",
        model: function () { return ss },
        success: function (data) {

            if (data && data.length > 0) {
                var _data = [];
                for (var i = 0; i < data.length; i++) {
                    if (data[i].PObjectID == ss) {
                        var obj = {};
                        obj.ObjectID = data[i].ObjectID;
                        obj.ObjectName = data[i].ObjectName;
                        obj.PObjectID = data[i].PObjectID;
                        obj.ObjectTypeDesc = data[i].ObjectTypeDesc;
                        obj.SN = data[i].SN;
                        obj.CreateTime = data[i].CreateTime;
                        obj.IsValid = data[i].IsValid;
                        //alert(data[i].ZJCount);
                        //obj.ZJCount = data[i].ZJCount;
                        getsubtree(data, data[i].ObjectID, obj);
                        _data.push(obj);

                    }
                }
                _menudata = data;
                $('#tableid').treegrid({
                    //title: 'TreeGrid',

                    width: screenwidth,
                    height: screenHeight,
                    nowrap: false,
                    rownumbers: false,
                    animate: true,
                    collapsible: true,
                    url: 'treegrid_data.json',
                    idField: 'ObjectID',
                    treeField: 'ObjectName',
                    remoteSort: false,
                    onLoadSuccess: function () {
                        $('#tableid').treegrid('collapseAll');
                    },       
                    //frozenColumns: [[{ title: '', field: 'ObjectID', width: 150}]],
                    columns: [[
                        { field: 'ObjectName', title: '', width: 150 },
                        { field: 'ZJCount', title: '钻井', width: 150, align: 'center',hidden:true },
                        { field: 'LJCount', title: '录井', width: 150, align: 'center' },
                        { field: 'CJCount', title: '测井', width: 150, align: 'center' },
                        { field: 'SYCount', title: '试油', width: 150, align: 'center' },
                        { field: 'FXHYCount', title: '分析化验', width: 150, align: 'center' },
                        { field: 'ObjectID', title: '其他', width: 150, align: 'center' },
                        { field: 'WZCZCount', title: '无值资产', width: 150, align: 'center' }

                        ]]

                });
                $('#tableid').treegrid('loadData', _data);

            }

        }
    });

    function getsubtree(_d, _pid, obj2) {
        if (_d && _d.length > 0) {
            var _sdata = [];
            for (var i = 0; i < _d.length; i++) {
                if (_d[i].PObjectID == _pid) {
                    var obj = {};
                    obj.ObjectID = _d[i].ObjectID;
                    obj.ObjectName = _d[i].ObjectName;
                    obj.PObjectID = _d[i].PObjectID;
                    obj.ObjectTypeDesc = _d[i].ObjectTypeDesc;
                    obj.SN = _d[i].SN;
                    obj.CreateTime = _d[i].CreateTime;
                    obj.IsValid = _d[i].IsValid
                    obj.ZJCount = _d[i].ZJCount;
                    obj.LJCount = _d[i].LJCount;
                    obj.CJCount = _d[i].CJCount;
                    obj.SYCount = _d[i].SYCount;
                    obj.FXHYCount = _d[i].FXHYCount;
                    obj.WZCZCount = _d[i].WZCZCount;
                    _sdata.push(obj);
                }
            }
            obj2.children = _sdata;
            if (_sdata.length > 0) {
                for (var j = 0; j < _sdata.length; j++) {
                    getsubtree(_d, _sdata[j].ObjectID, _sdata[j]);
                }
            }
        }
    }
}

//#endregion